<?php
error_reporting(E_ERROR|E_PARSE);
session_start();
if($_SESSION["islogin"]!=='igiveyouthepower'){
echo "<script language=JavaScript>\r\n";
echo "alert('请先登录!');\r\n";
echo "location.href='../index.php'\r\n";
echo "</script>";
}else{
require_once('../config.php');
$conn = mysqli_connect($cfg_dbhost,$cfg_dbuser,$cfg_dbpwd,$cfg_dbname);
function trimd($str){
$str=str_replace("'","''",$str);
return trim($str);
}
$proname=trimd($_POST["proname"]);
$skucode=$_POST["skucode"];
$price=$_POST["price"];
$saleprice=$_POST["saleprice"];
$coin=$_POST["coin"];
$code=$_POST["code"];
$kucun=$_POST["kucun"];
$weight=$_POST["weight"];
$bttname=$_POST["bttname"];
$sketch=trimd($_POST["sketch"]);
$keywords=trimd($_POST["keywords"]);
$content=trimd($_POST["content"]);
$bname=$_POST["bname"];
$fromurl=$_POST["fromurl"];
$platform=$_REQUEST["platform"];
$user_name=$_SESSION["managername"];
$ndate=date("Y-m-d",time());
if($proname==''){
echo "<script language=JavaScript>\r\n";
echo "alert('产品名不能为空!');\r\n";
echo "location.href='products_add.php'\r\n";
echo "</script>";
}else{
$sql = "INSERT INTO ph_products(proname,price,saleprice,skucode,coin,code,content,ndate,bname,user_name,sketch,keywords,weight,kucun,btname,fromurl,platform)VALUES('".$proname."','".$price."','".$saleprice."','".$skucode."','".$coin."','".$code."','".$content."','".$ndate."','".$bname."','".$user_name."','".$sketch."','".$keywords."','".$weight."','".$kucun."','".$bttname."','".$fromurl."','".$platform."')";
mysqli_query($conn,$sql);
$proid=mysqli_insert_id($conn);
//
$proimg=$_POST["proimg"];
for($i=0;$i<count($proimg);$i++){
mysqli_query($conn,"INSERT INTO ph_img(imgpath)VALUES('".$proimg[$i]."');");

$imginid=mysqli_insert_id($conn);

mysqli_query($conn,"INSERT INTO ph_proimg(imgid,proid)VALUES(".$imginid.",".$proid.");");
}
//
$btname=$_POST["btname"];
$btprice=$_POST["btprice"];
$btsaleprice=$_POST["btsaleprice"];
$btkucun=$_POST["btkucun"];
$upc=$_POST["upc"];
$imgid=$_POST["imgid"];
for($r=0;$r<count($btname);$r++){

mysqli_query($conn,"INSERT INTO ph_shuxing(cname,proid,price,saleprice,kucun,skucode)VALUES('".$btname[$r]."','".$proid."','".$btprice[$r]."','".$btsaleprice[$r]."','".$btkucun[$r]."','".$upc[$r]."');");
$btid=mysqli_insert_id($conn);
$btimg=$_POST["btimg".$imgid[$r]];
for($t=0;$t<count($btimg);$t++){
mysqli_query($conn,"INSERT INTO ph_img(imgpath)VALUES('".$btimg[$t]."');");

$imginbtid=mysqli_insert_id($conn);

mysqli_query($conn,"INSERT INTO ph_proimg(imgid,proid,btid)VALUES('".$imginbtid."','".$proid."','".$btid."');");
}
}

// echo "<script language=JavaScript>\r\n";
// echo "location.href='productslist.php?platform=".$platform."&bname=".$bname."'\r\n";
// echo "</script>";
}}
?>